/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package servlet;

import dao.MemberDao;
import entity.Member;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import service.DeleteCart;

@WebServlet("/dcas")
public class DeleteCartServlet extends HttpServlet{

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int bookId=Integer.parseInt(req.getParameter("id"));
        String username=(String)req.getSession().getAttribute("username");
        Member member=new MemberDao().getMemberByName(username);
        Boolean bool=new DeleteCart().deleteCart(member.getId(),bookId);
        if(bool==false){
            resp.setContentType("text/html;charset=utf-8");
            resp.getWriter().println("<h1>删除失败！</h1>");
            resp.getWriter().println("<a href='Cart.jsp'>返回购物车</a>");
        }
        else{
                resp.sendRedirect("Cart.jsp");
        }
    }
    
}
